<%@page import="java.util.HashMap"%>
<%@ page language="java" contentType="text/html"  pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="lcfms" uri="/WEB-INF/tld/lcfms.tld" %>	
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" href="${CSS}bootstrap.min.css"/>
	<link rel="stylesheet" href="${CSS}font-awesome.css"/>	
	<link rel="stylesheet" href="${CSS}widgets.css"/>
	<link rel="stylesheet" href="${CSS}b.page.bootstrap3.css" type="text/css">
	<link rel="stylesheet" href="${CSS}../../ace/css/tree.css" class="ace-main-stylesheet" id="main-ace-style" />
	<script src="${JS}jquery-3.2.1.min.js" type="text/javascript"></script>
	<script src="${JS}../../layer/layer.js"></script>
	<script src="${JS}bootstrap.min.js"></script>
	<script src="${JS}widgets.js" type="text/javascript"></script>	
	<script src="${JS}../../ace/js/jquery.nestable.min.js"></script>
	<style>
	.dd{max-width:100%;}
	.action-buttons>a{margin-right:10px;}
	</style>
</head>
<body>
<div class="container-fluid">
	<div class="row">
		<div class="widget-box  widget-color-blue" id="3061">
			<div class="widget-header widget-header-small">
				<h6 class="widget-title">
					<i class="fa fa-sort">
					</i>
					${title}
				</h6>	
				<div class="widget-toolbar">					
					<c:forEach items="${toolbar}" var="tool">
					<lcfms:if test="${tool.type eq 'js'}">
					<a href="javascript:void(0);" data-action="${tool.action}">
						<i class="fa ${tool.icon}">
						</i>					
					</a>	
					</lcfms:if>					
					</c:forEach>
				</div>
				<div class="widget-toolbar no-border">				
					<c:forEach items="${toolbar}" var="tool">					
					<lcfms:if test="${tool.type eq 'url'}">
					<button onclick="location.href='${tool.url}';" class="btn btn-xs btn-default smaller">
						<i class="fa ${tool.icon}"></i> ${tool.title}
					</button>
					</lcfms:if>
					<lcfms:elseif test="${tool.type eq 'tab'}">
					<button class="btn btn-xs btn-default smaller" onclick="openNewTab(${tool.itemId},'${tool.url}','${tool.itemName}');">
						<i class="fa ${tool.icon}"></i> ${tool.title}
					</button>
					</lcfms:elseif>
					<lcfms:elseif test="${tool.type eq 'layer'}">
					<button class="btn btn-xs btn-default smaller" onclick="openlayer('${tool.title}','${tool.icon}','${tool.url}',${tool.width},${tool.height});">
						<i class="fa ${tool.icon}"></i> ${tool.title}
					</button>
					</lcfms:elseif>
					<lcfms:elseif test="${tool.type eq 'function'}">
					<button class="btn btn-xs btn-default smaller" onclick="${tool.function}();">
						<i class="fa ${tool.icon}"></i> ${tool.title}
					</button>
					</lcfms:elseif>
					</c:forEach>
				</div>							
			</div>
			<div class="widget-body">
				<div class="widget-body-inner" style="display: block;">
					<div class="widget-main"  style="padding: 12px;">
					    <c:if test="${tableTopJsp ne null}">
						<jsp:include page="../${tableTopJsp}"/>
						</c:if>	
						<table id="tableBox" class="bTable table table-striped table-hover table-condensed">
							<thead>
								<tr>
								    <th style="width:5%;">${first}</th>
									<c:forEach items="${column}" var="col">	
									    <c:if test="${columnWidth.get(col)!=0}">
											<th style="width:${columnWidth.get(col)}px;">${col}</th>
										</c:if>																					
									</c:forEach>
									<th style="width:5%;">操作</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td colspan="${column.size()+2}" style="background: #fff;border: 0;padding: 0;">	
										<lcfms:if test="${treedata eq ''}">
											<div style="text-align:center;font-size:22px;clear:both;padding-top:20px">无数据</div>
										</lcfms:if>
										<lcfms:else>						
											<div class="dd dd-draghandle" id="nestable">${treedata}</div>
										</lcfms:else>						    	
									</td>
								</tr>
							</tbody>
						</table>				    										
					</div>
				</div>
			</div>		
		</div>
	</div>
</div>
<script>
widget.init();
$('#nestable').nestable();	
$('#nestable').children().find("li[close=true]").each(function(){
	$(this).addClass("dd-collapsed");
	$($(this).children("button")[0]).hide();
	$($(this).children("button")[1]).show();
});


function openNewTab(itemId,url,itemName){
	if(url.indexOf("http")==-1){
		var c="${USERINFO.mca[1]}".toLowerCase();
		url="${APP}${USERINFO.mca[0]}/"+c+"/"+url;
	}
	parent.openNewTab(itemId,url,itemName)	
}
function openlayer(title,icon,url,width,height){
	if(title=='删除' && icon=='fa-trash'){
		layer.confirm('您确定要删除吗？',{btn: ['是的','取消']}, function(){
			$.get(url,function(res){
				layer.msg(res.msg);
				if(res.code==1 && res.url){
					setTimeout(function(){
						location.href=res.url;
					},1000)
				}
			},'json');
		});
	}else{
		layer.open({
		      type: 2,
		      title: '<i class="fa '+icon+'"></i> '+title,
		      maxmin: true,
		      shadeClose: true, //点击遮罩关闭层
		      area : [width+'px' , height+'px'],
		      content: url
		});
	}	
}

function saveSort(){
	var dditem=$("#nestable .dd-item");
	var data=[];
	for(var i=0;i<dditem.length;i++){
		var itemId=$(dditem[i]).attr("data-id");
		var parentId=$(dditem[i]).parent().attr("parentId");
		if(parentId==null){
			parentId=$(dditem[i]).parent().parent().attr("data-id");
		}
		data.push({cid:itemId,pid:parentId});
	}
    $.post("${saveSortAction}",{data:JSON.stringify(data)},function(res){
    	layer.msg(res);
    });
}
</script>
</body>
</html>
 